/*
习题三
函子方法应用
*/

/*练习一*/
const fp = require('lodash/fp');
const { Maybe, Container } = require('./support');

let ex1 = () => {
    return fp.map(fp.add(1))
};
let maybe = Maybe.of([5, 6, 1]).map(ex1());
console.log(maybe);

/*练习二*/
let ex2 = ()=> fp.first;
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']).map(ex2());
console.log(xs);

/*练习三*/
let safeProp = fp.curry((x, o) => Maybe.of(o[x]));
let user = {id: 2, name: 'Albert'};
let ex3 = fp.first;
let firstName = safeProp('name', user).map(ex3);
console.log(firstName);

/*练习四*/
let ex4 = (n) => {
    const parsInt = Maybe.of(n).map(parseInt);
    return parsInt._value
};
console.log(ex4(3.00));
console.log(ex4());
